package com.th.supcom.pds.impl.service.internal.phamapply.command;

import java.util.List;
import java.util.Map;

import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.th.supcom.pds.domain.vo.InpPhamApplyDetailVO;
import com.th.supcom.pds.domain.vo.InpPhamDispenseDetailVO;
import com.th.supcom.pds.impl.common.enums.InpChargeIndicator;
import com.th.supcom.pds.impl.service.internal.phamapply.PhamDispenseConvertUtils;

/**
 * 药房摆药收费
 * 
 * @author leaqua@qq.com
 */
public class PhamDispenseCharge extends AbstractPhamApplyManagerBean implements Command
{

    @Override
    public boolean execute (Context arg0) throws Exception
    {
        PhamDispenseContext context = (PhamDispenseContext) arg0;
        List <InpPhamApplyDetailVO> applyDetail = context.getApplyDetailVOList ();
        List <InpPhamDispenseDetailVO> dispenseList = context.getInpPhamDispenseDetailVOList ();
        dispenseList = this.getAdapterBMSChargeService ().phamApplyCharge (dispenseList);
        // 将执行明细按照请领明细主键分组
        Map <Long, InpPhamDispenseDetailVO> patStockNoMap = PhamDispenseConvertUtils.convertListToMapByApplyId (dispenseList);
        // 药品出库后更新相应请领明细的出入库单据号
        for (InpPhamApplyDetailVO inpPhamApplyDetailVO : applyDetail)
        {
            // 如果清明明细存在对应的执行明细
            if (patStockNoMap.get (inpPhamApplyDetailVO.getInpPhamApplyDetailId ()) != null)
            {
                inpPhamApplyDetailVO.setChargeIndicator (InpChargeIndicator.Charged.getEnumCode ());
            }
        }
        context.setApplyDetailVOList (applyDetail);
        return false;
    }

    /** 日志记录器. */
    public static final Logger s_logger = LoggerFactory.getLogger (PhamDispenseCharge.class);

    /** 公司版权信息. */
    public static final String copyright = "Copyright 2014, TH Supcom Corporation";

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";

    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";
}
